#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<int>s[1000005],ans[1000005];
int n,m;
void dfs(int x,int y,int k,int num){
	if(k>num) return;
	if(y>m) y=1,x++;
	if(k==num||x>n){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(s[i][j]==1){
					int op=ans[i][j];
					op+=ans[i+1][j]+ans[i-1][j]+ans[i][j-1]+ans[i][j+1];
					if(!op) return;
				}
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(s[i][j]==0) cout<<'.';
				else if(ans[i][j]==1) cout<<1;
				else cout<<0;
			}cout<<'\n';
		}
		exit(0);
	}
	if(s[x][y]==1){
		ans[x][y]=1;dfs(x,y+1,k+1,num);
		ans[x][y]=0,dfs(x,y+1,k,num);
	}
	else dfs(x,y+1,k,num);
}
signed main(){
	freopen("indian.in","r",stdin);
	freopen("indian.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int j=0;j<=m+1;j++) s[0].push_back(0),s[n+1].push_back(0),ans[0].push_back(0),ans[n+1].push_back(0);
	for(int i=1;i<=n;i++){
		s[i].push_back(0);
		for(int j=1;j<=m;j++){
			char x;cin>>x;
			if(x=='#') s[i].push_back(1);
			else s[i].push_back(0);
		}
		s[i].push_back(0);
	}
	int c=0,sum=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]==1){
				sum++;
				if(s[i+1][j]!=1) c++;
				if(s[i-1][j]!=1) c++;
				if(s[i][j-1]!=1) c++;
				if(s[i][j+1]!=1) c++;
			}
		}
	}
	if((c+sum)/5>=sum){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(s[i][j]==1)cout<<s[i][j];
				else cout<<'.';
			}cout<<'\n';
		}return 0;
	}
	for(int i=1;i<=n;i++){for(int j=0;j<=1+m;j++){ans[i].push_back(0);}}
	dfs(1,1,0,(c+sum)/5);
	return 0;
}
